package com.ruoyi.project.commodity.brands.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.commodity.brands.domain.GoodsBrands;
import com.ruoyi.project.commodity.brands.service.IGoodsBrandsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品品牌Controller
 * 
 * @author 艾有宏
 * @date 2021-01-19
 */
@Controller
@RequestMapping("/commodity/brands")
public class GoodsBrandsController extends BaseController
{
    private String prefix = "commodity/brands";

    @Autowired
    private IGoodsBrandsService goodsBrandsService;

    @RequiresPermissions("commodity:brands:view")
    @GetMapping()
    public String brands()
    {
        return prefix + "/brands";
    }

    /**
     * 查询商品品牌列表
     */
    @RequiresPermissions("commodity:brands:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsBrands goodsBrands)
    {
        startPage();
        List<GoodsBrands> list = goodsBrandsService.selectGoodsBrandsList(goodsBrands);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌列表
     */
    @RequiresPermissions("commodity:brands:export")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsBrands goodsBrands)
    {
        List<GoodsBrands> list = goodsBrandsService.selectGoodsBrandsList(goodsBrands);
        ExcelUtil<GoodsBrands> util = new ExcelUtil<GoodsBrands>(GoodsBrands.class);
        return util.exportExcel(list, "brands");
    }

    /**
     * 新增商品品牌
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品品牌
     */
    @RequiresPermissions("commodity:brands:add")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsBrands goodsBrands)
    {
        return toAjax(goodsBrandsService.insertGoodsBrands(goodsBrands));
    }

    /**
     * 修改商品品牌
     */
    @GetMapping("/edit/{brandId}")
    public String edit(@PathVariable("brandId") Long brandId, ModelMap mmap)
    {
        GoodsBrands goodsBrands = goodsBrandsService.selectGoodsBrandsById(brandId);
        mmap.put("goodsBrands", goodsBrands);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品品牌
     */
    @RequiresPermissions("commodity:brands:edit")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsBrands goodsBrands)
    {
        return toAjax(goodsBrandsService.updateGoodsBrands(goodsBrands));
    }

    /**
     * 删除商品品牌
     */
    @RequiresPermissions("commodity:brands:remove")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsBrandsService.deleteGoodsBrandsByIds(ids));
    }

    @RequiresPermissions("commodity:brands:enable")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PostMapping( "/enable")
    @ResponseBody
    public AjaxResult enable(Long id)
    {
        return toAjax(goodsBrandsService.enableGoodsBrandsById(id));
    }

    @RequiresPermissions("commodity:brands:disable")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PostMapping( "/disable")
    @ResponseBody
    public AjaxResult disable(Long id)
    {
        return toAjax(goodsBrandsService.disableGoodsBrandsById(id));
    }

}
